package com.aldobucchi.x.Array
{
	import com.aldobucchi.core.comparison.ComparisonUtil;
	import com.aldobucchi.core.comparison.result.ComparisonResults;
	import com.aldobucchi.core.comparison.simple.ISimpleComparator;
	

	public class ObjectArrayUtil
	{


		public static function extractColumn( arr:Array, fieldName:String ):Array
		{
			var newArr:Array = [];
			
			try
			{
				for each ( var obj:Object in arr )
				{
					newArr.push( obj[ fieldName ] );				
				}
			} catch ( e:Error ){}
			
			return newArr;
		}



		public static function indexOfInColumn( arr:Array, value:*, columnName:String, comparator:ISimpleComparator = null ):int
		{
			for ( var i:int=0; i<arr.length; i++ )
			{
				var row:Object = arr[ i ];
				if ( row.hasOwnProperty( columnName ) && ( ComparisonUtil.compare( row[ columnName ], value, comparator ) == ComparisonResults.EQUAL ) )
						return i;
			}		
			return -1;		
		}
	
	}
	
}